/*
 * Filename:    StorageController.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-1-4
 */
package com.paic.mhis.hcpms.common.storage.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.common.storage.biz.service.HcpmsStorageService;
import com.paic.mhis.hcpms.common.storage.dto.HcpmsStorageDTO;
import com.paic.mhis.hcpms.common.storage.util.StorageContentUtil;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

@Controller
@RequestMapping("hcpmsStorage")
public class StorageController {
	@BizServicesProxy
	private HcpmsStorageService hcpmsStorageService;

	@RequestMapping("queryStorageDataMap.do")
	@ResponseBody
	public Map<String, Object> queryStorageDataMap(@ModelAttribute HcpmsStorageDTO vo, HttpServletRequest request)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		vo.setUserId(user.getUsername());
		map.put("result", hcpmsStorageService.getStorageDataMap(vo));
		map.put("massage", StorageContentUtil.QUERY_RETURN_TRUE);
		map.put("state", StorageContentUtil.QUERY_STATE_TRUE);

		return map;
	}

	@RequestMapping("queryStorageList.do")
	@ResponseBody
	public Map<String, Object> queryStorageList(@ModelAttribute HcpmsStorageDTO vo, HttpServletRequest request)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		vo.setUserId(user.getUsername());
		map.put("result", hcpmsStorageService.getStorageDataList(vo));
		map.put("massage", StorageContentUtil.QUERY_RETURN_TRUE);
		map.put("state", StorageContentUtil.QUERY_STATE_TRUE);
		return map;
	}

	@RequestMapping("queryStorageData.do")
	@ResponseBody
	public Map<String, Object> queryStorageData(@ModelAttribute HcpmsStorageDTO vo, HttpServletRequest request)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		vo.setUserId(user.getUsername());
		map.put("result", hcpmsStorageService.getStorageData(vo));
		map.put("massage", StorageContentUtil.QUERY_RETURN_TRUE);
		map.put("state", StorageContentUtil.QUERY_STATE_TRUE);
		return map;
	}

	@RequestMapping("saveStorageData.do")
	@ResponseBody
	public Map<String, Object> saveStorageData(@ModelAttribute HcpmsStorageDTO vo, HttpServletRequest request)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		vo.setUserId(user.getUsername());
		hcpmsStorageService.saveStorageData(vo, false);
		map.put("massage", StorageContentUtil.SAVE_RETURN_TRUE);
		map.put("state", StorageContentUtil.QUERY_STATE_TRUE);
		return map;
	}
}
